<template>
  <el-dialog
    :title="title"
    :visible.sync="dialogFormVisible"
    width="800px"
    @close="close"
  >
    <el-descriptions
      ref="form"
      class="margin-top"
      title="房源信息"
      :column="3"
      border
      :model="form"
    >
      <el-descriptions-item>
        <template slot="label">
          <i class="el-icon-document"></i>
          项目信息
        </template>
        <el-tag size="small">
          {{ form.realEstate.projectName }}
        </el-tag>
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">
          <i class="el-icon-collection-tag"></i>
          房源类型
        </template>
        <el-tag size="small">
          {{ form.realEstate.estateType }}
        </el-tag>
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">
          <i class="el-icon-c-scale-to-original"></i>
          地产信息
        </template>
        <el-tag size="small">
          {{ form.realEstate.estateName }}
        </el-tag>
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">
          <i class="el-icon-office-building"></i>
          楼栋
        </template>
        <el-tag size="small" type="success">
          {{ form.realEstate.building }}
        </el-tag>
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">
          <i class="el-icon-school"></i>
          单元
        </template>
        <el-tag size="small" type="success">
          {{ form.realEstate.unit }}
        </el-tag>
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">
          <i class="el-icon-house"></i>
          房间号
        </template>
        <el-tag size="small" type="success">{{ form.realEstate.num }}</el-tag>
      </el-descriptions-item>

      <el-descriptions-item>
        <template slot="label">
          <i class="el-icon-location-outline"></i>
          审核状态
        </template>
        <el-tag
          size="small"
          :type="
            form.realEstateReview.reviewStatus == 1
              ? 'info'
              : form.realEstateReview.reviewStatus == 2
              ? 'success'
              : 'error'
          "
        >
          {{
            form.realEstateReview.reviewStatus == 1
              ? '待审核'
              : form.realEstateReview.reviewStatus == 2
              ? '已通过'
              : '未通过'
          }}
        </el-tag>
      </el-descriptions-item>
      <el-descriptions-item>
        <template slot="label">
          <i class="el-icon-location-outline"></i>
          地址
        </template>
        <el-tag size="small" type="info">
          {{ form.realEstate.address }}
        </el-tag>
      </el-descriptions-item>
    </el-descriptions>
    <el-input
      v-model="textarea"
      type="textarea"
      :rows="2"
      placeholder="请输入备注"
      required
      :disabled="form.realEstateReview.reviewStatus != 1"
    >
      >
    </el-input>
    <div slot="footer" class="dialog-footer">
      <el-button
        v-if="form.realEstateReview.reviewStatus == 1"
        type="danger"
        size="small"
        @click="confirm(true)"
      >
        不通过审核
      </el-button>
      <el-button
        v-if="form.realEstateReview.reviewStatus == 1"
        type="primary"
        size="small"
        @click="confirm(false)"
      >
        通过审核
      </el-button>
    </div>
  </el-dialog>
</template>

<script>
  import { reviewRealEstate } from '@/api/house'
  import { parseTime } from '@/utils/index'
  import _ from 'lodash'
  export default {
    name: 'BindEdit',
    data() {
      return {
        // setStatus: {},
        textarea: '通过审核',
        form: {
          realEstate: {
            projectName: '',
            estateName: '',
            estateType: '',
            address: '',
            building: 0,
            unit: 0,
            num: 0,
          },
        },
        title: '',
        dialogFormVisible: false,
      }
    },
    created() {},
    methods: {
      showEdit(row) {
        if (!row) {
          this.title = '添加'
        } else {
          this.title = '审核表单'
          console.log(row)
          // this.setStatus = _.cloneDeep(row)
          this.form = _.cloneDeep(row)
        }
        this.dialogFormVisible = true
      },
      close() {
        this.dialogFormVisible = false
        // console.log(this.form.realEstateReview)
        this.$emit('fetch-data')
      },
      async confirm(value) {
        let _form = _.cloneDeep(this.form.realEstateReview)
        _form.evaluate = this.textarea
        _form.userId = this.form.userInfo.userId
        _form.reviewStatus = value ? 3 : 2
        const time = new Date()
        _form.reviewTime = parseTime(time)
        const { data } = await reviewRealEstate(_form)
        if (data.status == 0) {
          // this.setStatus.realEstateReview.reviewStatus = 2
          this.$emit('fetch-data')
          this.$baseMessage(data.message, 'success')
          this.dialogFormVisible = false
        } else {
          // this.setStatus.realEstateReview.reviewStatus = 3
          // if (value) {
          //   this.$emit('fetch-data')
          //   this.dialogFormVisible = false
          // } else {
          this.$baseMessage(data.message, 'error')
          // }
        }
      },
    },
  }
</script>
